// components/shopping-product/index.js
import componentBehaviors from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { DELIVERY_TYPE } from '../../../constants/activity';

Component({
    behaviors: [componentBehaviors],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        show: {
            type: Boolean,
            value: false,
        },
        originInfo: {
            type: Object,
            value: {},
        },
        cartInfo: {
            type: Object,
            value: {},
        },
    },
    data: {
        deliveryType: {
            map: DELIVERY_TYPE,
        },
    },
    methods: {
        handleClose: function () {
            this.setData({
                show: false,
            });
            this.triggerEvent('close');
        },
        handleProductClick(e) {
            this.triggerEvent('click', e.detail);
        },
        handleProductChange(e) {
            this.triggerEvent('change', e.detail);
        },
        handleEnsure() {
            const { cartInfo, originInfo } = this.data;
            if (!cartInfo.list.length || cartInfo.totalPrice < originInfo.minimumPurchaseAmount) {
                return;
            }
            this.triggerEvent('ensure');
            this.handleClose();
        },
    }
})
